import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/widget/app_bar_back_widget.dart';
import 'package:yysk_app/widget/app_bar_title_widget.dart';

class CustomAppBar2 extends StatelessWidget implements PreferredSizeWidget {
  final String title;
  final BuildContext context;
  final List<Widget>? actions;
  final VoidCallback? onBack;
  final VoidCallback? beforBack;
  final Widget? titleWidget;
  final bool isNeedWidget;
  final Widget? child;
  final bool showChild;
  final Color? textColors;
  final Color? backgroundColor;
  final double maxWidth;
  const CustomAppBar2({
    super.key,
    required this.title,
    required this.context,
    this.actions,
    this.onBack,
    this.beforBack,
    this.titleWidget = const Text(''),
    this.isNeedWidget = false,
    this.textColors = AppColors.fontColor,
    this.backgroundColor = AppColors.backgroundColor,
    this.child,
    this.showChild = false,
    this.maxWidth = 280,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      // color: AppColors.fontColorGreen,
      width: context.width,
      height: preferredSize.height,
      decoration: BoxDecoration(),
      // color: AppColors.fontColorGreen,
      child: Stack(
        children: [
          Center(
            child:
                showChild
                    ? child
                    : Container(
                      constraints: BoxConstraints(
                        maxWidth: maxWidth == 280 ? 280.px : maxWidth,
                      ),
                      child: Text(
                        title,
                        style: TextStyle(
                          color: textColors,
                          fontSize: 18.px,
                          overflow: TextOverflow.ellipsis,
                          fontWeight: FontWeight.normal,
                        ),
                      ),
                    ),
          ),
          Positioned(
            left: -10.px,
            top: 0.px,
            child: Container(
              decoration: BoxDecoration(
                // color: AppColors.backgroundColorEnd06,
              ),

              height: preferredSize.height,
              child: AppBarBackWidget(
                context: context,
                onBack: onBack,
                beforBack: beforBack,
                backgroundColor: backgroundColor,
              ),
            ),
          ),
          Positioned(
            right: 10.px,
            top: 0.px,
            child: Container(
              height: preferredSize.height,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: actions?.isNotEmpty == true ? actions! : [],
              ),
            ),
          ),
        ],
      ),
    );
  }

  @override
  Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
